<?php

namespace frontend\modules\general\controllers;

use frontend\modules\common\controllers\BaseController;
use frontend\modules\resource\logic\SpecialLogic;
use Yii;
use frontend\modules\resource\models\SpecialResourceSearch;
use yii\web\NotFoundHttpException;

/**
 * SpecialResourceController implements the CRUD actions for HySpecialResource model.
 */
class SpecialResourceController extends BaseController
{
    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
        $this->branchAdmin();
        $this->checkSpecialId();
    }

    /**
     * Lists all HySpecialResource models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new SpecialResourceSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $this->branchId, $this->specialId);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * 批量删除接口
     * @return string
     * @throws \yii\base\ExitException
     */
    public function actionBatchRemove()
    {

        $id = Yii::$app->request->post('id');
        $id = json_decode($id, true);
        (new SpecialLogic())->checkBranchSpecialResource($id, $this->branchId);
        $res = (new SpecialLogic())->RemoveBranchSpecial($id, $this->branchId);
        return $this->suc(['data' => $res, 'msg' => '移除完成']);
    }
}
